#!/usr/bin/env bash

# 当使用未初始化的变量时，程序自动退出
# 也可以使用命令 set -o nounset
set -u

# 当任何一行命令执行失败时，自动退出脚本
# 也可以使用命令 set -o errexit
set -e

# 在执行(execute)脚本之前，打印出执行命令
set -x

SOURCE_CODE_BASE_PATH="/Users/dolphin/source/dabai/microservice"
LOG_PATH="/var/log/shell"
USER_NAME="jiangxiaoqiang"
PASSWORD="\$mygitlab225843"

arr=("soa-misc" "soa-misc-biz" "ws-red-envelope" "soa-goblin" "soa-room" "soa-tick")

for index in "${!arr[@]}"; do
  cd ${SOURCE_CODE_BASE_PATH}/"${arr[$index]}"
  if [ "${arr[$index]}" == "soa-misc" ]; then
    git remote set-url origin https://jiangxiaoqiang:\$my@gitlab.dolphin.com/development/soa-misc.git
    git pull
  elif [ "${arr[$index]}" == "soa-misc-biz" ]; then
    git remote set-url origin https://jiangxiaoqiang:\$my@gitlab.dolphin.com/development/soa-misc-biz.git
    git pull origin master
  elif [ "${arr[$index]}" == "ws-red-envelope" ]; then
    git remote set-url origin https://jiangxiaoqiang:\$my@gitlab.dolphin.com/development/ws-red-envelope.git
    git pull origin master
  elif [ "${arr[$index]}" == "soa-goblin" ]; then
    git remote set-url origin https://jiangxiaoqiang:\$my@gitlab.dolphin.com/development/soa-goblin.git
    git pull origin develop
  elif [ "${arr[$index]}" == "soa-room" ]; then
    git remote set-url origin https://jiangxiaoqiang:\$my@gitlab.dolphin.com/development/soa-room.git
    git pull origin master
  elif [ "${arr[$index]}" == "soa-tick" ]; then
    git remote set-url origin https://jiangxiaoqiang:\$my@gitlab.dolphin.com/development/soa-tick.git
    git pull origin develop
  else
    git pull origin master
  fi
  echo "update ${arr[$index]}" >>${LOG_PATH}/update-source.log
done
